package com.idc.config.security.sys;

import com.idc.config.security.plugins.SimpleUserDetails;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.HashSet;
import java.util.Set;

/**
 * @author Trump
 * @version 1.0.0
 * @ClassName FakeSysmangerServiceImpl.java
 * @Description 模拟 SysmangerService
 * @createTime 2019年08月15日 14:07:00
 */
public class FakeSysmangerServiceImpl implements SysmangerService, InitializingBean {

    private Set<SimpleUserDetails> cache = new HashSet<>();

    @Override
    public void afterPropertiesSet() throws Exception {
        cache.add(new SimpleUserDetails("trump", "$${{123456}}$$", "特靠谱", "13188888888"));
        cache.add(new SimpleUserDetails("li", "$${{123456}}$$", "李雷雷", "15188888888"));
    }

    @Override
    public String getMobileLoginCode(String mobile) {
        return "000000";
    }

    @Override
    public String getLoginAcctByMobile(String mobile) {
        return cache.stream().filter(item -> item.getMobile().equals(mobile)).findFirst().get().getLoginAcct();
    }

    @Override
    public UserDetails loadUserDetailsByLoginAcct(String loginAcct) {
        return cache.stream().filter(item -> item.getLoginAcct().equals(loginAcct)).findFirst().get();
    }
}
